rm(list = ls())
#working_folder<- "/Users/bgpopescu/Library/CloudStorage/Dropbox/covid_institutions/"
working_folder<-"//Mac/Dropbox-1/covid_paper_replication/"
setwd(working_folder)

#This is to obtain:
#-figure_a17a
#-figure_a17b
#-figure_a18a
#-figure_a18b
#-figure_a18c
#-figure_a18d
#-figure_a18e
#-figure_a18f
#-figure_a18g
#-figure_a18h
#-figure_a18i
#-figure_a18j
#-figure_a18k
#-figure_a18l
#-figure_a18m
#-figure_a18n
#-figure_a18o
#-figure_a18p
#-figure_a18r
#-figure_a18s
#-figure_a18t
#-figure_a18u
#-figure_a18v
#-figure_a18x
#-figure_a18y
#-figure_a18z
#-figure_ab18a
#-figure_ab18b
#-figure_ab18c
#-figure_ab18d

library("readxl")
library("reshape")
library("stringi")
library("stringr")
library("dplyr")
library("tidyr")
library("stargazer")
#library("rgdal")
library("corrplot")
library("Hmisc")
library("ggplot2")
library("glue")
library('gridExtra')
library('grid')
library('lfe')
library('broom')
library("plm")
library("multiwayvcov")
library("lmtest")
library("psych")
#library("rgeos")
library("ggrepel")
library("lemon")
library("sandwich")
library("spdep")
library("xtable")
library('gsynth')
library("pracma")
library("conleyreg")
library("vars")
library("rlist")
#library("rdrop2")
library("fastDummies")
library("dplyr")
library("berryFunctions")
library("mediation")
library("sp")
library("pgirmess")
library("fwildclusterboot")
library("tidyverse")
library("geojsonsf")


#############
#Covid Cases#
#############

covid_cases <- read_csv("./data/Covid cases_Risklayer.csv")
covid_cases<-as.data.frame(covid_cases)
names(covid_cases)


names(covid_cases)<-stri_trans_general(names(covid_cases), "Latin-ASCII")
covid_cases<-subset(covid_cases, select=-c(ADMIN, Population))
names_df<-names(covid_cases)
names_df<-names_df[names_df != c("AGS")]

mdata <- melt(covid_cases, id=c("AGS"), measured=names_df)
mdata$date<-gsub("[a-zA-Z ]", "", mdata$variable)
mdata$date<-as.Date(mdata$date, "%d.%m.%Y")
mdata<-subset(mdata, format(as.Date(date),"%Y")!=2021)
mdata$week <- as.character(strftime(mdata$date,format="%W"))
names(mdata)[names(mdata) == "value"] <- "covid_cases"
mdata$AGS<-as.numeric(as.character(mdata$AGS))
mdata$ags_date<-paste(mdata$AGS, mdata$date, sep = "_")
rm(covid_cases)

##################
#Reading Mobility#
##################

my_data2 <- read_csv("./data/Mobility_changes_full.csv")
my_data2<-as.data.frame(my_data2)

names(my_data2)<-stri_trans_general(names(my_data2), "Latin-ASCII")
names_df2<-names(my_data2)
my_data2<-subset(my_data2, select=-c(Kreisname))
names_df2<-names_df[names_df2 != c("Kreisschlussel", "Kreisname")]
mdata2 <- melt(my_data2, id=c("Kreisschlussel"), measured=names_df2)
rm(my_data2)
mdata2$date<-gsub("[a-zA-Z ]", "", mdata2$variable)
mdata2$date<-as.Date(mdata2$date, "%d/%m/%Y")
mdata2<-subset(mdata2, format(as.Date(date),"%Y")!=2021)
mdata2$week <- as.character(strftime(mdata2$date,format="%W"))
names(mdata2)[names(mdata2) == "value"] <- "mobility"
mdata2$Kreisschlussel<-as.numeric(as.character(mdata2$Kreisschlussel))
mdata2<-subset(mdata2, select = -c(variable, week))
mdata2$ags_date<-paste(mdata2$Kreisschlussel, mdata2$date, sep = "_")
#rm(my_data2)


##########################
#Merge mobility and covid#
##########################

covid_mob<-left_join(mdata2, mdata, by = c("ags_date"="ags_date"))
rm(mdata2, mdata)
covid_mob2<-subset(covid_mob, select = -c(ags_date, AGS, date.y))
rm(covid_mob)
names(covid_mob2)[names(covid_mob2) == "date.x"] <- "date"
covid_mob2$covid_cases<-ifelse(is.na(covid_mob2$covid_cases), 0, covid_mob2$covid_cases)
covid_mob2$week <- as.character(strftime(covid_mob2$date,format="%W"))
covid_mob2$diff <- ave(covid_mob2$covid_cases , covid_mob2$Kreisschlussel , FUN=function(i) c(NA,diff(i)))
#Attention: We turn negative cases to 0 because Germany changes the way they count cases
covid_mob2$diff <- ifelse(covid_mob2$diff<0, 0, covid_mob2$diff)
summary(covid_mob2$diff)

result_day <- covid_mob2 %>% 
  dplyr::group_by(date, Kreisschlussel) %>% 
  dplyr::summarize(mean_mobil = mean(mobility), 
                   sum_mobil = sum(mobility),
                   sum_covid = sum(diff), 
                   sum_cumulative_covid = sum(covid_cases))



data_cov_mob = geojson_sf("./data/data_cov_mob.geojson")
data_cov_mob2<-subset(data_cov_mob, week=="00")
states<-subset(data_cov_mob2, select = c(SN_L, Bundesland, AGS, GEN))
states$Bundesland[is.na(states$Bundesland) & states$SN_L=="05"]<-"Nordrhein-Westfalen"
states$Bundesland[is.na(states$Bundesland) & states$SN_L=="08"]<-"Baden-Württemberg"
states$Bundesland[is.na(states$Bundesland) & states$SN_L=="09"]<-"Bayern"
states$Bundesland[is.na(states$Bundesland) & states$SN_L=="13"]<-"Mecklenburg-Vorpommern"
states$Bundesland[is.na(states$Bundesland) & states$SN_L=="16"]<-"Thüringen"



states<-st_drop_geometry(states)
states$AGS<-as.numeric(states$AGS)
covid_mob2$Kreisschlussel<-as.numeric(covid_mob2$Kreisschlussel)
result_dayx<-left_join(covid_mob2, states, by = c("Kreisschlussel" = "AGS"))
result_dayx$GEN[result_dayx$GEN=="Osnabrück" & result_dayx$Kreisschlussel==03404]<-"Osnabrück, Stadt"
result_dayx_Niedersachsen<-subset(result_dayx, Bundesland == "Niedersachsen")

result_day_lands <- result_dayx %>% 
  dplyr::group_by(week, Bundesland) %>% 
  dplyr::summarize(mean_mobil = mean(mobility), 
                   sum_mobil = sum(mobility),
                   sum_covid = sum(diff), 
                   sum_cumulative_covid = sum(covid_cases))

result_day_lands_day <- result_dayx %>% 
  dplyr::group_by(date, Bundesland) %>% 
  dplyr::summarize(mean_mobil = mean(mobility), 
                   sum_mobil = sum(mobility),
                   sum_covid = sum(diff), 
                   sum_cumulative_covid = sum(covid_cases))

#result_dayx$Kreisschlussel
result_week <- result_dayx %>% 
  dplyr::group_by(week, Kreisschlussel) %>% 
  dplyr::summarize(mean_mobil = mean(mobility), 
                   sum_mobil = sum(mobility),
                   sum_covid = sum(diff), 
                   sum_cumulative_covid = sum(covid_cases))
result_week<-left_join(result_week, states, by = c("Kreisschlussel" = "AGS"))
result_week$GEN[result_week$GEN=="Osnabrück" & result_week$Kreisschlussel==03404]<-"Osnabrück, Stadt"
result_week$GEN[result_week$GEN=="Kassel" & result_week$Kreisschlussel==06611]<-"Kassel, Stadt"
result_week$GEN[result_week$GEN=="Karlsruhe" & result_week$Kreisschlussel==08212]<-"Karlsruhe, Stadt"
result_week$GEN[result_week$GEN=="Heilbronn" & result_week$Kreisschlussel==08121]<-"Heilbronn, Stadt"
result_week$GEN[result_week$GEN=="Augsburg" & result_week$Kreisschlussel==09761]<-"Augsburg, Stadt"
result_week$GEN[result_week$GEN=="Bamberg" & result_week$Kreisschlussel==09461]<-"Bamberg, Stadt"
result_week$GEN[result_week$GEN=="Coburg" & result_week$Kreisschlussel==09463]<-"Coburg, Stadt"
result_week$GEN[result_week$GEN=="Fürth" & result_week$Kreisschlussel==09563]<-"Fürth, Stadt"
result_week$GEN[result_week$GEN=="Hof" & result_week$Kreisschlussel==09464]<-"Hof, Stadt"
result_week$GEN[result_week$GEN=="München" & result_week$Kreisschlussel==9162]<-"München, Stadt"
result_week$GEN[result_week$GEN=="Passau" & result_week$Kreisschlussel==09262]<-"Passau, Stadt"
result_week$GEN[result_week$GEN=="Regensburg" & result_week$Kreisschlussel==09362]<-"Regensburg, Stadt"
result_week$GEN[result_week$GEN=="Rosenheim" & result_week$Kreisschlussel==09163]<-"Rosenheim, Stadt"
result_week$GEN[result_week$GEN=="Rostock" & result_week$Kreisschlussel==13003]<-"Rosenheim, Stadt"
result_week$GEN[result_week$GEN=="Schweinfurt" & result_week$Kreisschlussel==09662]<-"Kreisfreie Stadt"
result_week$GEN[result_week$GEN=="Ansbach" & result_week$Kreisschlussel==9561]<-"Ansbach Stadt"
result_week$GEN[result_week$GEN=="Aschaffenburg" & result_week$Kreisschlussel==09661]<-"Aschaffenburg Stadt"
result_week$GEN[result_week$GEN=="Bayreuth" & result_week$Kreisschlussel==9472]<-"Bayreuth Stadt"
result_week$GEN[result_week$GEN=="Würzburg" & result_week$Kreisschlussel==9663]<-"Würzburg Stadt"
result_week$GEN[result_week$GEN=="Landshut" & result_week$Kreisschlussel==9261]<-"Landshut Stadt"
result_week$GEN[result_week$GEN=="Leipzig" & result_week$Kreisschlussel==14713]<-"Leipzig Stadt"



result_day_kreis <- result_dayx
result_week$week_numeric<-as.numeric(result_week$week) + 1


result_dayx_Niedersachsen<-subset(result_day_lands, Bundesland == "Niedersachsen")
result_dayx_Niedersachsen2b<-subset(result_day_kreis, Bundesland == "Niedersachsen")
result_dayx_Niedersachsen2c<-subset(result_week, Bundesland == "Niedersachsen")
unique(result_week$Bundesland)
result_dayx_Schleswig_Holstein2c<-subset(result_week, Bundesland == "Schleswig-Holstein")
max(result_week$mean_mobil)
min(result_week$mean_mobil)
result_dayx_hamburg<-subset(result_week, Bundesland == "Hamburg")
result_dayx_bremen<-subset(result_week, Bundesland == "Bremen")
result_dayx_nordrhein_westfalen<-subset(result_week, Bundesland == "Nordrhein-Westfalen")
result_dayx_nordrhein_hessen<-subset(result_week, Bundesland == "Hessen")
result_dayx_nordrhein_rheinland_pfalz<-subset(result_week, Bundesland == "Rheinland-Pfalz")
result_dayx_nordrhein_badenwurttemberg<-subset(result_week, Bundesland == "Baden-Württemberg")
result_dayx_nordrhein_bayern<-subset(result_week, Bundesland == "Bayern")
result_dayx_multiple<-subset(result_week, Bundesland == "Berlin" | Bundesland == "Bremen" | Bundesland == "Hamburg")


states_bayern<-subset(states, Bundesland == "Bayern")
states_bayern <- states_bayern[order(states_bayern$GEN),]
nrow(states_bayern)/2
states_bayern1<-head(states_bayern, nrow(states_bayern)/2)
states_bayern1_ags<-states_bayern1$AGS
states_bayern2<-tail(states_bayern, nrow(states_bayern)/2)
states_bayern2_ags<-states_bayern2$AGS

result_dayx_nordrhein_bayern1<-subset(result_dayx_nordrhein_bayern, Kreisschlussel %in% states_bayern1_ags)
result_dayx_nordrhein_bayern2<-subset(result_dayx_nordrhein_bayern, Kreisschlussel %in% states_bayern2_ags)



result_dayx_nordrhein_saarland<-subset(result_week, Bundesland == "Saarland")
result_dayx_nordrhein_berlin<-subset(result_week, Bundesland == "Berlin")
result_dayx_nordrhein_brandenburg<-subset(result_week, Bundesland == "Brandenburg")
result_dayx_nordrhein_mecklenburg_vorpommern<-subset(result_week, Bundesland == "Mecklenburg-Vorpommern")
result_dayx_nordrhein_sachsen<-subset(result_week, Bundesland == "Sachsen")
result_dayx_nordrhein_sachsen_anhalt<-subset(result_week, Bundesland == "Sachsen-Anhalt")
result_dayx_nordrhein_thuringen<-subset(result_week, Bundesland == "Thüringen")


result_dayx_Niedersachsen2b$Kreisschlussel<-as.factor(result_dayx_Niedersachsen2b$Kreisschlussel)
result_dayx_Niedersachsen2c$Kreisschlussel<-as.factor(result_dayx_Niedersachsen2c$Kreisschlussel)
result_dayx_Niedersachsen2c$kreis_gen<-paste0(result_dayx_Niedersachsen2c$GEN, result_dayx_Niedersachsen2c$Kreisschlussel, sep="")
result_day_lands$week_numeric<-as.numeric(result_day_lands$week)+1





graph_states_day<-ggplot(result_day_lands_day, aes(x = date, y = mean_mobil, color = Bundesland, group = Bundesland)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,130,10), limits = c(-60,130))+
  scale_x_date(date_breaks = "1 month", date_minor_breaks = "1 week",
               date_labels = "%B")+
  #scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_hline(yintercept = 0, color ="red")+
  geom_vline(xintercept = as.numeric(as.Date("2020-03-02")), color ="red")+
  labs(x = "Month", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="States",
                              nrow = 4))+
  theme(axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.x  = element_text(size=12, angle = 45, vjust = 1, hjust=1),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=7))
graph_states_day<-reposition_legend(graph_states_day, 'top left')
ggsave(graph_states_day, file = "./paper/graphs/figure_a17a.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)




graph_states<-ggplot(result_day_lands, aes(x = week_numeric, y = mean_mobil, color = Bundesland, group = Bundesland)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,140,10), limits = c(-60,140))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="States",
                              nrow = 4))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=7))
graph_states<-reposition_legend(graph_states, 'top left')
ggsave(graph_states, file = "./paper/graphs/figure_a17b.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)


counties_niedersachsen<-ggplot(result_dayx_Niedersachsen2c, aes(x = week_numeric, y = mean_mobil, color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,140,10), limits = c(-60,140))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=5))
counties_niedersachsen<-reposition_legend(counties_niedersachsen, 'top left')
ggsave(counties_niedersachsen, file = "./paper/graphs/figure_a18a.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)


counties_niedersachsen_zoom<-ggplot(result_dayx_Niedersachsen2c, aes(x = week_numeric, y = mean_mobil, color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,140,10), limits = c(-60,140))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=5))
counties_niedersachsen_zoom<-reposition_legend(counties_niedersachsen_zoom, 'top left')
ggsave(counties_niedersachsen_zoom, file = "./paper/graphs/figure_a18b.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_schleswig_holstein<-ggplot(result_dayx_Schleswig_Holstein2c, aes(x = week_numeric, y = mean_mobil, color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=7))
counties_schleswig_holstein<-reposition_legend(counties_schleswig_holstein, 'top left')
ggsave(counties_schleswig_holstein, file = "./paper/graphs/figure_a18c.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_schleswig_holstein_zoom<-ggplot(result_dayx_Schleswig_Holstein2c, aes(x = week_numeric, y = mean_mobil, color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=7))
counties_schleswig_holstein_zoom<-reposition_legend(counties_schleswig_holstein_zoom, 'top left')
ggsave(counties_schleswig_holstein_zoom, file = "./paper/graphs/figure_a18d.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)





counties_nordrhein_westfalen<-ggplot(result_dayx_nordrhein_westfalen, aes(x = week_numeric, 
                                                                          y = mean_mobil, color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 9))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=5))
counties_nordrhein_westfalen<-reposition_legend(counties_nordrhein_westfalen, 'top left')
ggsave(counties_nordrhein_westfalen, file = "./paper/graphs/figure_a18e.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_nordrhein_westfalen_zoom<-ggplot(result_dayx_nordrhein_westfalen, aes(x = week_numeric, 
                                                                               y = mean_mobil, color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 9))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=5))
counties_nordrhein_westfalen_zoom<-reposition_legend(counties_nordrhein_westfalen_zoom, 'top left')
ggsave(counties_nordrhein_westfalen_zoom, file = "./paper/graphs/figure_a18f.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)




result_dayx_nordrhein_hessen$kreis_gen<-paste0(result_dayx_nordrhein_hessen$GEN, result_dayx_nordrhein_hessen$Kreisschlussel, sep="")


counties_nordrhein_hessen<-ggplot(result_dayx_nordrhein_hessen, aes(x = week_numeric, y = mean_mobil, 
                                                                    color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=7))
counties_nordrhein_hessen<-reposition_legend(counties_nordrhein_hessen, 'top left')
ggsave(counties_nordrhein_hessen, file = "./paper/graphs/figure_a18g.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_nordrhein_hessen_zoom<-ggplot(result_dayx_nordrhein_hessen, aes(x = week_numeric, y = mean_mobil, 
                                                                         color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=7))
counties_nordrhein_hessen_zoom<-reposition_legend(counties_nordrhein_hessen_zoom, 'top left')
ggsave(counties_nordrhein_hessen_zoom, file = "./paper/graphs/figure_a18h.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)




counties_nordrhein_rheinland_pfalz<-ggplot(result_dayx_nordrhein_rheinland_pfalz, 
                                           aes(x = week_numeric, y = mean_mobil, 
                                               color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_nordrhein_rheinland_pfalz<-reposition_legend(counties_nordrhein_rheinland_pfalz, 'top left')
ggsave(counties_nordrhein_rheinland_pfalz, file = "./paper/graphs/figure_a18i.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)




counties_nordrhein_rheinland_pfalz_zoom<-ggplot(result_dayx_nordrhein_rheinland_pfalz, 
                                                aes(x = week_numeric, y = mean_mobil, 
                                                    color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_nordrhein_rheinland_pfalz_zoom<-reposition_legend(counties_nordrhein_rheinland_pfalz_zoom, 'top left')
ggsave(counties_nordrhein_rheinland_pfalz_zoom, file = "./paper/graphs/figure_a18j.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)


result_dayx_nordrhein_badenwurttemberg$kreis_gen<-paste0(result_dayx_nordrhein_badenwurttemberg$GEN, result_dayx_nordrhein_badenwurttemberg$Kreisschlussel, sep="")


counties_nordrhein_badenwurttemberg<-ggplot(result_dayx_nordrhein_badenwurttemberg, 
                                            aes(x = week_numeric, y = mean_mobil, 
                                                color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=4))
counties_nordrhein_badenwurttemberg<-reposition_legend(counties_nordrhein_badenwurttemberg, 'top left')
ggsave(counties_nordrhein_badenwurttemberg, file = "./paper/graphs/figure_a18k.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)




counties_nordrhein_badenwurttemberg_zoom<-ggplot(result_dayx_nordrhein_badenwurttemberg, 
                                                 aes(x = week_numeric, y = mean_mobil, 
                                                     color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=4))
counties_nordrhein_badenwurttemberg_zoom<-reposition_legend(counties_nordrhein_badenwurttemberg_zoom, 'top left')
ggsave(counties_nordrhein_badenwurttemberg_zoom, file = "./paper/graphs/figure_a18l.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



result_dayx_nordrhein_bayern$kreis_gen<-paste0(result_dayx_nordrhein_bayern$GEN, result_dayx_nordrhein_bayern$Kreisschlussel, sep="")
result_dayx_nordrhein_bayernx<-subset(result_dayx_nordrhein_bayern, week=="01")
length(result_dayx_nordrhein_bayernx)
result_dayx_nordrhein_bayernx2<-subset(result_dayx_nordrhein_bayernx, duplicated(GEN))

counties_nordrhein_bayern1<-ggplot(result_dayx_nordrhein_bayern1, 
                                   aes(x = week_numeric, y = mean_mobil, 
                                       color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=4))
counties_nordrhein_bayern1<-reposition_legend(counties_nordrhein_bayern1, 'top left')
ggsave(counties_nordrhein_bayern1, file = "./paper/graphs/figure_a18m.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)


counties_nordrhein_bayern1_zoom<-ggplot(result_dayx_nordrhein_bayern1, 
                                        aes(x = week_numeric, y = mean_mobil, 
                                            color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=4))
counties_nordrhein_bayern1_zoom<-reposition_legend(counties_nordrhein_bayern1_zoom, 'top left')
ggsave(counties_nordrhein_bayern1_zoom, file = "./paper/graphs/figure_a18n.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)





counties_nordrhein_bayern2<-ggplot(result_dayx_nordrhein_bayern2, 
                                   aes(x = week_numeric, y = mean_mobil, 
                                       color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=4))
counties_nordrhein_bayern2<-reposition_legend(counties_nordrhein_bayern2, 'top left')
ggsave(counties_nordrhein_bayern2, file = "./paper/graphs/figure_a18o.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_nordrhein_bayern2_zoom<-ggplot(result_dayx_nordrhein_bayern2, 
                                        aes(x = week_numeric, y = mean_mobil, 
                                            color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=4))
counties_nordrhein_bayern2_zoom<-reposition_legend(counties_nordrhein_bayern2_zoom, 'top left')
ggsave(counties_nordrhein_bayern2_zoom, file = "./paper/graphs/figure_a18p.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)






counties_nordrhein_saarland<-ggplot(result_dayx_nordrhein_saarland, 
                                    aes(x = week_numeric, y = mean_mobil, 
                                        color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_nordrhein_saarland<-reposition_legend(counties_nordrhein_saarland, 'top left')
ggsave(counties_nordrhein_saarland, file = "./paper/graphs/figure_a18q.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)





counties_nordrhein_saarland_zoom<-ggplot(result_dayx_nordrhein_saarland, 
                                         aes(x = week_numeric, y = mean_mobil, 
                                             color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_nordrhein_saarland_zoom<-reposition_legend(counties_nordrhein_saarland_zoom, 'top left')
ggsave(counties_nordrhein_saarland_zoom, file = "./paper/graphs/figure_a18r.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)










counties_nordrhein_brandenburg<-ggplot(result_dayx_nordrhein_brandenburg, 
                                       aes(x = week_numeric, y = mean_mobil, 
                                           color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_nordrhein_brandenburg<-reposition_legend(counties_nordrhein_brandenburg, 'top left')
ggsave(counties_nordrhein_brandenburg, file = "./paper/graphs/figure_a18s.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_nordrhein_brandenburg_zoom<-ggplot(result_dayx_nordrhein_brandenburg, 
                                            aes(x = week_numeric, y = mean_mobil, 
                                                color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_nordrhein_brandenburg_zoom<-reposition_legend(counties_nordrhein_brandenburg_zoom, 'top left')
ggsave(counties_nordrhein_brandenburg_zoom, file = "./paper/graphs/figure_a18t.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)







counties_mecklenburg_vorpommern<-ggplot(result_dayx_nordrhein_mecklenburg_vorpommern, 
                                        aes(x = week_numeric, y = mean_mobil, 
                                            color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_mecklenburg_vorpommern<-reposition_legend(counties_mecklenburg_vorpommern, 'top left')
ggsave(counties_mecklenburg_vorpommern, file = "./paper/graphs/figure_a18u.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_mecklenburg_vorpommern_zoom<-ggplot(result_dayx_nordrhein_mecklenburg_vorpommern, 
                                             aes(x = week_numeric, y = mean_mobil, 
                                                 color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_mecklenburg_vorpommern_zoom<-reposition_legend(counties_mecklenburg_vorpommern_zoom, 'top left')
ggsave(counties_mecklenburg_vorpommern_zoom, file = "./paper/graphs/figure_a18v.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)




counties_nordrhein_sachsen<-ggplot(result_dayx_nordrhein_sachsen, 
                                   aes(x = week_numeric, y = mean_mobil, 
                                       color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_nordrhein_sachsen<-reposition_legend(counties_nordrhein_sachsen, 'top left')
ggsave(counties_nordrhein_sachsen, file = "./paper/graphs/figure_a18x.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_nordrhein_sachsen_zoom<-ggplot(result_dayx_nordrhein_sachsen, 
                                        aes(x = week_numeric, y = mean_mobil, 
                                            color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_nordrhein_sachsen_zoom<-reposition_legend(counties_nordrhein_sachsen_zoom, 'top left')
ggsave(counties_nordrhein_sachsen_zoom, file = "./paper/graphs/figure_a18y.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)




counties_thuringen<-ggplot(result_dayx_nordrhein_thuringen, 
                           aes(x = week_numeric, y = mean_mobil, 
                               color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_thuringen<-reposition_legend(counties_thuringen, 'top left')
ggsave(counties_thuringen, file = "./paper/graphs/figure_a18z.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)


counties_thuringen_zoom<-ggplot(result_dayx_nordrhein_thuringen, 
                                aes(x = week_numeric, y = mean_mobil, 
                                    color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_thuringen_zoom<-reposition_legend(counties_thuringen_zoom, 'top left')
ggsave(counties_thuringen_zoom, file = "./paper/graphs/figure_ab18a.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)




counties_multiple<-ggplot(result_dayx_multiple, 
                          aes(x = week_numeric, y = mean_mobil, 
                              color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(1,53,3), limits = c(1,53))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_multiple<-reposition_legend(counties_multiple, 'top left')
ggsave(counties_multiple, file = "./paper/graphs/figure_ab18b.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)



counties_multiple_zoom<-ggplot(result_dayx_multiple, 
                               aes(x = week_numeric, y = mean_mobil, 
                                   color = GEN, group = GEN)) +
  geom_line()+
  theme_bw()+
  scale_y_continuous(name = "Mobility Compared to 2019", breaks=seq(-62,135,10), limits = c(-65,135))+
  scale_x_continuous(name = "Week", breaks=seq(5,15,1), limits = c(5,15))+
  geom_vline(xintercept = 10, color ="red")+
  geom_hline(yintercept = 0, color ="red")+
  labs(x = "Week", y = "Mobility Compared to 2019")+
  theme_bw() +
  guides(color = guide_legend(title="County",
                              nrow = 7))+
  theme(axis.text.x = element_text(size=12),
        axis.text.x.top  = element_text(size=10, angle = 45, margin=margin(5,5,10,5,"pt")),
        axis.text.y = element_text(size=12),
        axis.title=element_text(size=12),
        plot.title = element_text(hjust = 0.5),
        legend.position='bottom',
        #Legend.position values should be between 0 and 1. c(0,0) corresponds to the "bottom left"
        #and c(1,1) corresponds to the "top right" position.
        legend.box.background = element_rect(fill='white'),
        legend.background = element_blank(),
        legend.text=element_text(size=6))
counties_multiple_zoom<-reposition_legend(counties_multiple_zoom, 'top left')
ggsave(counties_multiple_zoom, file = "./paper/graphs/figure_ab18c.jpg", 
       height = 12, width = 20, 
       units = "cm", dpi = 200)

